<?php

/**
 *  
 */
class AdminSiteUserPermissionCategoryController extends AdminBaseController
{
    /**
     *  before ...
     */
    public function beforeAction($action)
    {
        parent::beforeAction($action);

        if( !$this->permissionManager->checkRole('work_manager') ) {
            Request::redirect('admin/');
        }

        $this->menus->setFocusByAction('adminSiteUserPermissionCategory/list');
        return true;
    }

    /**
     *  index
     */
    public function actionIndex()
    {
        Request::redirect('list');
    }

    /**
     *  list
     */
    public function actionList( $page=1, $searchKey='' )
    {
        if( Request::isPost() ) {
            $posts = Request::getPostInfo();
            if( $posts['searchKey'] ) {
                $searchKey = $posts['searchKey'];
            }
        }

        $userPermissionCategories = new UserPermissionCategories();
        $myUserPermissionCategories = $userPermissionCategories->getUserPermissionCategories( $searchKey, $page );
        $rowCount = $userPermissionCategories->getNumUserPermissionCategories( $searchKey );

        $pageLimit = new PageLimitManager();
        $pageLimit->setBaseUrl( $this->createUrl('') );
        $pageLimit->setRowCount( $rowCount );
        $pageLimit->setPageShowCount( BaseMapper::DEFAULT_ROW_COUNT );
        $pageLimit->setPage( $page );
        $pageLimit->setSearchKey( $searchKey );

        $this->render('list',array(
            'searchKey' => $searchKey,
            'page' => $page,
            'userPermissionCategories' => $myUserPermissionCategories, 
            'pageLimit' => $pageLimit 
        ));
    }

}
